<template>
	<div>
		<div class="layout-breadcrumb">
			<Breadcrumb>
			    <BreadcrumbItem href="/">首页</BreadcrumbItem>
			    <BreadcrumbItem href="">系统配置</BreadcrumbItem>
			    <BreadcrumbItem href="/config/admin">后台用户管理</BreadcrumbItem>
			</Breadcrumb>
		</div>
		<div class="layout-content">
		    <div class="layout-content-main">
		    	<Row :gutter="16"><ICol span="6"><router-link to="/config/admin/update" v-if="this.$store.getters.per.config_admin_create" ><IButton type="primary">添加新用户</IButton></router-link></ICol></Row>
		    	<BaseTable ref="table" :url="table.url" :header="table.header" ></BaseTable>
		    </div>
		</div>
	</div>
</template>
<script>
import {Row,Col} from 'iview/src/components/grid';
import Button from 'iview/src/components/button';
import Breadcrumb from 'iview/src/components/breadcrumb';
import IButton from 'iview/src/components/button';

import BaseTable  from 'admin/components/table/base';
import Axios from 'admin/config/axios';

export default{
	components:{
        Row,
        'ICol':Col,
        'IButton' : Button,
        Breadcrumb,
        'BreadcrumbItem' : Breadcrumb.Item,
        BaseTable,
    },
    data () {
        return {
        	table:{
        		url : '/config/admin/view/list',
        		header: []
        	},
        }
    },
    methods:{
    	resetTable(param){
    		this.$refs['table'].tableData(param);
    	},
    },
    created:function(){
    	this.table.header =  [
            {
		        title: '登录名',
		        key: 'name'
		    },
		    {
		        title: '操作',
		        key: 'action',
		        width: 150,
		        align: 'center',
		        render: (h, params) => {
		            return h('div', [
		            	!this.$store.getters.per.config_admin_update ? '' :
		                h(IButton, {
		                    props: {
		                        type: 'primary',
		                        size: 'small'
		                    },
		                    style: {
		                        marginRight: '5px'
		                    },
		                    on: {
		                        click: () => {
		                        	this.$router.push('/config/admin/update/'+params.row.id);
		                        }
		                    }
		                }, '编辑'),
		                !this.$store.getters.per.config_admin_delete ? '' :
		                h(IButton, {
		                    props: {
		                        type: 'error',
		                        size: 'small'
		                    },
		                    on: {
		                        click: () => {
		                        	this.$Modal.confirm({
					                    title: '你确定要删除吗？',
					                    content: '一旦删除无法恢复',
					                    onOk: () => {
					                        Axios.Config.Admin.Del(params.row.id)
								            .then(res =>{
								                if(!res) return false;
								                this.$refs.table.tableRowDel = true;
								                this.$refs.table.tableData();
								            })
					                    }
					                });
		                        }
		                    }
		                }, '删除')
		            ]);
		        }
		    }
        ];
    }
}
</script>